<%@page import="java.util.HashSet"%>
<%@ page import="serverDB.*" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.HashMap" %>

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CleverDropBox</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/arial.js"></script>
<script type="text/javascript" src="js/cuf_run.js"></script>

</head>
<body>
<% 	if(!(Boolean)session.getAttribute("logedIn")) 
		response.sendRedirect("index.jsp");

	ConnectToDataBase connectToDataBase = ConnectToDataBase.getInst();
	Client client = connectToDataBase.regetClient((Client)session.getAttribute("client"));
	HashMap<String,Set<String>> tagsTyp = new HashMap<String,Set<String>>();
	Set<String> tagsTypeNames = new HashSet<String>();
	Set<Box> boxes = client.getBoxes();
	int counter=0;
	
	for(Box box : boxes){
		Set<File> files = box.getFiles();
		
		for(File file : files){
			Set<Tages> tags = file.getTages();
			
			for(Tages tag : tags){
				Set<String> tagsList = tagsTyp.get(tag.getTagType());
				if(tagsList!=null){
					System.out.println("t ");
					if(tagsList.add(tag.getTag()))
						counter++;
				}
				else{
					tagsList = new HashSet<String>();
					tagsList.add(tag.getTag());
					tagsTyp.put(tag.getTagType(),tagsList);
					tagsTypeNames.add(tag.getTagType());
					counter++;
				}
				System.out.println("sw "+tagsTypeNames.size());
			}
		}
	}
	session.setAttribute("numOfSearch",counter);
%>
<div class="main2">
  <div class="header">
    <div class="header_resize">
      <div class="logo">
        <h1><a href="index.jsp">Clever<span>DropBox</span></a></h1>
      </div>
      <div class="menu_nav">
        <ul>
          <li><a href="index.jsp"><span>Home</span></a></li>
          <li class="active"><a href="users.jsp"><span>Users</span></a></li>
          <li><a href="support.html"><span>Support</span></a></li>
          <li><a href="aboutUs.jsp"><span>About Us</span></a></li>
          <li><a href="contactUs.jsp"><span>Contact Us</span></a></li>
        </ul>
        <div class="clr"></div>
      </div>
      <div class="clr"></div>
    </div>
  </div>
  <div class="clr"></div>
  <div class="content">
  <div class="infobar">
     <%= session.getAttribute("userName") %> &nbsp;&nbsp;&nbsp;&nbsp;
     <a href= "LogOutServlet">logout</a>
    </div>
    <div class="clr"></div>
    <div class="content_resize">
      <div class="mainbar">
        <div class="article">
        	<form action="SearchServlet">
        	<%
        	System.out.println("sw "+tagsTypeNames.size());
        	for(String tagType : tagsTypeNames){
        	%>
        		<div class="advancedSearch">
        		<h4><%=tagType %></h4>
        		<%
        		Set<String> tagsList = tagsTyp.get(tagType);
        		int i=0;
        		for(String tagValue : tagsList){
        		%>
        			<input type="checkbox" name="search<%=i%>" value="<%=tagValue%>"/> <%= tagValue%><br/>
        		<% 
        			i++;
        		}
        		%>
        		</div>
        	<%
        	}
        	%>
        	<br />
        	<input type="image" src="images/searchButton.png" class="send" /> 
        	</form>
        </div>
      </div>
      <div class="sidebar">
        <div class="search">
          <form id="form" name="form" method="post" action="SearchServlet">
            <span>
            <input name="search0" type="text" class="keywords" id="search" maxlength="50" value="Search..." />
            <input name="b" type="image" src="images/search.gif" class="button" />
            </span>
          </form>
        </div>
        <div class="gadget">
          <h2>Menu</h2>
          <div class="clr"></div>
          <ul class="sb_menu">
          	<li><a href="logedIn2.jsp">My Boxes</a></li>
            <li><a href="uploadFile.jsp">Upload File</a></li>
            <li><a href="advancedSearch.jsp">Advanced Search</a></li>
            <li><a href="newBox.jsp">Create New Box</a></li>
            <li><a href="shareBox.jsp">Share Box</a></li>
          </ul>
        </div>
        
        <div class="gadget">
          <h2>Wise Words</h2>
          <div class="clr"></div>
          <p> <img src="images/test_1.gif" alt="" width="19" height="20" /> <em>We can let circumstances rule us, or we can take charge and rule our lives from within </em>.<img src="images/test_2.gif" alt="" width="19" height="20" /></p>
          <p style="float:right;"><strong>Earl Nightingale</strong></p>
        </div>
      </div>

      <div class="clr"></div>
    </div>
  </div>
  <div class="fbg">
    <div class="fbg_resize">
      
      <div class="clr"></div>
    </div>
    <div class="footer">
      <p class="lf">&copy; Copyright <a href="#">MyWebSite</a>.</p>
      <p class="rf">Layout by Cool <a href="http://www.coolwebtemplates.net/">Website Templates</a></p>
      <div class="clr"></div>
    </div>
  </div>
</div>
</body>
</html>
